package com.lihepeng.leecode.frequency.ArrayList;

import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 两数之和
 * 2022年5月10日
 * lihp
 */
public class Solution50 {
    public int[] twoSum (int[] numbers, int target) {
        if (numbers ==null || numbers.length  ==0) {
            return new int[0];
        }
        HashMap<Integer,Integer> paramMap = new HashMap<>();
        for (int i=0;i<numbers.length;i++) {
            if (paramMap.containsKey(target - numbers[i])) {
                int[] ints = new int[2];
                ints[0] = paramMap.get(target-numbers[i])+1;
                ints[1] = i+1;
                return ints;
            }else {
                paramMap.put(numbers[i],i);
            }
        }
        return new int[0];
    }
    @Test
    public void runTest(){
        int []arrs = {3,2,4};
        int result = 6;
        int[] ints = twoSum(arrs, result);
        System.out.println(Arrays.toString(ints));
    }
}
